﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace TSComm.Utilities
{
    /// <summary>
    /// 正则表达式通用类
    /// </summary>
    public class RegexHelper
    {
        #region 验证输入字符串是否与模式字符串匹配
        /// <summary>
        /// 验证输入字符串是否与模式字符串匹配，匹配返回true
        /// </summary>
        /// <param name="input">输入字符串</param>
        /// <param name="pattern">模式字符串</param>        
        public static bool IsMatch(string input, string pattern)
        {
            return IsMatch(input, pattern, RegexOptions.IgnoreCase);
        }

        /// <summary>
        /// 验证输入字符串是否与模式字符串匹配，匹配返回true
        /// </summary>
        /// <param name="input">输入的字符串</param>
        /// <param name="pattern">模式字符串</param>
        /// <param name="options">筛选条件</param>
        public static bool IsMatch(string input, string pattern, RegexOptions options)
        {
            return Regex.IsMatch(input, pattern, options);
        }

        /// <summary>
        /// 替换字符串。
        /// </summary>
        /// <param name="input">原字符串</param>
        /// <param name="patten">针对原字符串的正则表达式</param>
        /// <param name="replacement">被替换后的字符串</param>
        /// <returns></returns>
        public static string Replace(string input, string patten,string replacement)
        {
            return Regex.Replace(input, patten,replacement,RegexOptions.IgnoreCase);
        }

        /// <summary>
        /// 替换字符串。
        /// </summary>
        /// <param name="input">原字符串</param>
        /// <param name="patten">针对原字符串的正则表达式</param>
        /// <param name="replacement">被替换后的字符串</param>
        /// <param name="options">筛选条件</param>
        /// <returns></returns>
        public static string Replace(string input, string patten, string replacement,RegexOptions options)
        {
            return Regex.Replace(input, patten, replacement, options);
        }

        #endregion
    }
}
